{extend name="base" /}

{block name="title"}商店{/block}

{block name="main"}
<div class="countgo pull-left">
	<div class="zt">
		<div class="remain">
			<div class="page-header long-header"><h3>庄园管理 <small> 商店</small></h3></div>
			<div>
				<ol class="breadcrumb">
					<li><span class="glyphicon glyphicon-home"></span><a href="/">主页</a></li>
					<li><a href="#">交易系统</a></li>
					<li class="active">商店</li>
				</ol>
			</div>

			<div class="panel panel-default">
				<div class="panel-heading">
					您的金币余额：<span class="text-danger" id="gold"></span>
				</div>

	  			<table class="long_table">
	  				<tr class="tb_top">
						<td align="center">商品名称</td>
						<td align="center">单价(个)</td>
						<td align="center">数量</td>
						<!--<td align="center">小计</td>-->
						<td align="center">操作</td>
					</tr>
					{php}
						$FRUIT_FIRST_LIMIT_EACH_PRICE = getFarmParam('FRUIT_FIRST_LIMIT_EACH_PRICE');
						$FRUIT_SECOND_LIMIT_EACH_PRICE = getFarmParam('FRUIT_SECOND_LIMIT_EACH_PRICE');
					{/php}
					<tr>
						<td align="center"><h5><strong>额度种子</strong></h5></td>
						<td align="center"><h5><strong>{$FRUIT_FIRST_LIMIT_EACH_PRICE}</strong></h5></td>
						<td align="center">
							<div class="input-group" style="width:130px;">
								<!--<span class="input-group-btn"><button class="btn btn-default j_jian" type="button"><span class="glyphicon glyphicon-minus"></span></button></span>
								<input type="text" class="form-control" value="0" maxlength="3">
								<span class="input-group-btn"><button class="btn btn-default j_jia" type="button"><span class="glyphicon glyphicon-plus"></span></button></span>-->
								<input type="text" class="form-control" id="handleBuyFirstNum" value="1" maxlength="6" />
							</div>
						</td>
						<td align="center"><a href="javascript:buy('handleBuyFirst', {$FRUIT_FIRST_LIMIT_EACH_PRICE});" class="btn btn-danger">立即购买</a></td>
					</tr>

					<tr>
						<td align="center"><h5><strong>收益种子</strong></h5></td>
						<td align="center"><h5><strong>{$FRUIT_SECOND_LIMIT_EACH_PRICE}</strong></h5></td>
						<td align="center">
							<div class="input-group" style="width:130px;">
								<input type="text" class="form-control"  id="handleBuySecondNum" value="1" maxlength="6" />
							</div>
						</td>
						<td align="center"><a href="javascript:buy('handleBuySecond', {$FRUIT_SECOND_LIMIT_EACH_PRICE});" class="btn btn-danger">立即购买</a></td>
					</tr>
	  			</table>
			</div>
		</div>
	</div>
</div>

{/block}
{block name="script"}
	<script type="text/javascript">
		var gold = $('#gold');
		var price = {$userWallet -> gold};
		gold.text(price);

		function buy(handle, eachPrice) {
			if(confirm('确认购买？')) {
				var num = parseInt($('#' + handle + 'Num').val());
				if(num <= 0) {
					layer.msg('请输入正确数量!');
					return false;
				}

				if((num * eachPrice) > price) {
					layer.msg('您的金币不足!');
					return false;
				}

				tishi2();
				
				price -= num * eachPrice;
				$.post('/shop/' + handle, {num: num}, function(result) {
					tishi2close();

					gold.text(price);

					layer.msg(result['message']);
				});
			}
		}
	</script>
{/block}